﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;

namespace WebApplication.Admin
{
    public partial class BaoCaoXuatNhapVo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadMatHang();
                Microsoft.Reporting.WebForms.ReportDataSource source;
                DateTime dt = Commomcs.convertDate(DateTime.Now.ToString("dd/MM/yyyy"));
                string ngay = dt.ToString("dd/MM/yyyy");
                    source = new Microsoft.Reporting
                   .WebForms.ReportDataSource("BaoCaoNhapVo", new Baocao.BaoCaoXuatNhapVo().GetXuatNhapVo(ngay, dt));
                    ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoXuatVo.rdlc";
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportViewer1.LocalReport.DataSources.Add(source);
                    ReportViewer1.LocalReport.Refresh();
            }
        }

        protected void lbtnxem_Click(object sender, EventArgs e)
        {
            LoadDl();

        }
        public void LoadDl()
        {
            Microsoft.Reporting.WebForms.ReportDataSource source;
            DateTime dt = Commomcs.convertDate(DateTime.Now.ToString("dd/MM/yyyy"));
            string ngay = dt.ToString("dd/MM/yyyy");
            if (Dlmathang.SelectedValue.Equals("0"))
            {
                source = new Microsoft.Reporting
               .WebForms.ReportDataSource("BaoCaoNhapVo", new Baocao.BaoCaoXuatNhapVo().GetXuatNhapVo(ngay,dt));
                ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoXuatVo.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }
            else
            {
                DateTime dts = Commomcs.convertDate(datepicker.Text);
                string ngay1 = dts.ToString("dd/MM/yyyy");
                string mamh=Dlmathang.SelectedValue;
                source = new Microsoft.Reporting
               .WebForms.ReportDataSource("BaoCaoNhapVo", new Baocao.BaoCaoXuatNhapVo().GetXuatNhapVo(ngay1,dts,mamh));
                ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoXuatVo.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }

        }
        public void LoadMatHang()
        {
            IUnitOfWork iunitfwork = new EFUnitOfWork();
            MATHANGRepository repository = new MATHANGRepository(new EFRepository<MATHANG>(), iunitfwork);
            IQueryable<MATHANG> objmathang = repository.All();
            Dlmathang.DataSource = objmathang;
            Dlmathang.DataValueField = "MAMH";
            Dlmathang.DataTextField = "TENMH";
            Dlmathang.DataBind();
            Dlmathang.Items.Insert(0, new ListItem { Text = "---Chọn mặt hàng---", Value = "0" });
        }
    }
}